package org.dey.controller;

import com.github.pagehelper.PageHelper;
import org.dey.entity.Result;
import org.dey.pojo.*;
import org.dey.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin
public class MedicalAppointmentController {

    //预约列表
    @Autowired
    OrderService orderService;

    //检查组
    @Autowired
    CheckGroupService checkGroupService;

    //检查项
    @Autowired
    CheckItemService checkItemService;

    //套餐
    @Autowired
    SetmealService setmealService;

    //预约设置
    @Autowired
    OrderSettingService orderSettingService;


    //预约列表信息
    @PostMapping("orderXx.do/{pageNum}/{pagesize}")
    public PageVo<Order> yuYueLbXx(@RequestBody Order order,
                                   @PathVariable Integer pageNum,
                                   @PathVariable Integer pagesize) {
        PageVo<Order> list = orderService.yuYueLbXx(order,pageNum,pagesize);
        return list;
    }

    //预约列表增加
    @PostMapping("order.do")
    public Result zjYuYueLbXx(@RequestBody Order order) {
        Result num = orderService.zjYuYueLbXx(order);
        return num;
    }

    //预约列表删除
    @DeleteMapping("order.do/{id}")
    public int scYuYueLbXx(@PathVariable int id) {
        int num = orderService.scYuYueLbXx(id);
        return num;
    }

    //预约列表修改
    @PutMapping("order.do")
    public int xgYuYueLbXx(@RequestBody Order order) {
        System.out.println(order);
        return orderService.xgYuYueLbXx(order);
    }


    @PostMapping("checkItemXx.do/{pageNum}/{pagesize}")
    public PageVo<CheckItem> checkItemXx(@RequestBody CheckItem checkItem,
                                         @PathVariable Integer pageNum,
                                         @PathVariable Integer pagesize) {

        PageVo<CheckItem> list = checkItemService.checkItemXx(checkItem, pageNum, pagesize);

        return list;
    }

    //检查项全部信息
    @GetMapping("checkItemXxqb.do/{id}")
    public List<CheckItem> checkItemXxqb(@PathVariable int id) {
        List<CheckItem> list = checkItemService.checkItemXxqb(id);
        return list;
    }

    //增加检查项
    @PostMapping("checkItem.do")
    public Result zjCheckItemXx(@RequestBody CheckItem checkItem) {
        Result num = checkItemService.zjCheckItemXx(checkItem);
        return num;
    }

    //删除删除检查项
    @DeleteMapping("checkItem.do/{code}")
    public Result scCheckItemXx(@PathVariable String code) {
        Result num = checkItemService.scCheckItemXx(code);
        return num;
    }

    //根据检查项编码查询数据
    @GetMapping("checkItem.do/{code}")
    public CheckItem cxCheckItemXxBYcode(@PathVariable String code) {
        return checkItemService.cxCheckItemXxBYcode(code);
    }

    //修改检查项
    @PutMapping("checkItem.do")
    public Result xgCheckItemXx(@RequestBody CheckItem checkItem) {
        return checkItemService.xgCheckItemXx(checkItem);
    }


    //检查组信息查询
    @PostMapping("checkGroupXx.do/{pageNum}/{pagesize}")
    public PageVo<CheckGroup> checkGroupXx(@RequestBody CheckGroup checkGroup,
                                           @PathVariable int pageNum,
                                           @PathVariable int pagesize) {
        PageVo<CheckGroup> list = checkGroupService.checkGroupXx(checkGroup, pageNum, pagesize);
        return list;
    }



    //增加检查组
    @PostMapping("checkGroup.do")
    public Result zjCheckGroupXx(@RequestBody CheckGroup checkGroup) {
        Result result = checkGroupService.zjCheckGroupXx(checkGroup);
        return result;
    }

    //删除检查组
    @DeleteMapping("checkGroup.do/{id}")
    public Result scCheckGroupXx(@PathVariable int id) {
        Result num = checkGroupService.scCheckGroupXx(id);
        return num;
    }

    //根据检查组id查询数据
    @GetMapping("checkGroup.do/{id}")
    public CheckGroup cxCheckGroupXxBYid(@PathVariable int id) {
        return checkGroupService.cxCheckGroupXxBYid(id);
    }

    //根据检查组id去查找它包含的检查项
    @GetMapping("ckjianchaxiang.do/{id}")
    public List<CheckItem> kcjcx(@PathVariable int id) {
        return checkGroupService.kcjcx(id);
    }

    //修改检查组
    @PutMapping("checkGroup.do")
    public int xgCheckGroupXx(@RequestBody CheckGroup checkGroup) {
        return checkGroupService.xgCheckGroupXx(checkGroup);
    }

    //给检查组添加检查项
    @PostMapping("addjcztjjcx.do/{id}")
    public int  addjcztjjcx(@PathVariable int id,
                            @RequestBody CheckItem[] checkItem) {

        int addjcztjjcx = checkGroupService.addjcztjjcx(id, checkItem);
        return addjcztjjcx;
    }


    //检查组信息查询
    @PostMapping("SetmealXx.do/{pageNum}/{pagesize}")
    public PageVo<Setmeal> setmealXx(@RequestBody Setmeal setmeal,
                                           @PathVariable int pageNum,
                                           @PathVariable int pagesize) {
        PageVo<Setmeal> list = setmealService.setmealXx(setmeal, pageNum, pagesize);
        return list;
    }


    //增加套餐
    @PostMapping("Setmeal.do")
    public Result zjSetmealXx(@RequestBody Setmeal setmeal) {
        Result num = setmealService.zjSetmealXx(setmeal);
        return num;
    }

    //删除套餐
    @DeleteMapping("Setmeal.do/{id}")
    public Result scSetmealXx(@PathVariable int id) {
        Result num = setmealService.scSetmealXx(id);
        return num;
    }

    //根据套餐id查询数据
    @GetMapping("Setmeal.do/{id}")
    public Setmeal cxSetmealXxBYid(@PathVariable int id) {
        return setmealService.cxSetmealXxBYid(id);
    }

    //修改套餐
    @PutMapping("Setmeal.do")
    public int xgSetmealXx(@RequestBody Setmeal setmeal) {
        return setmealService.xgSetmealXx(setmeal);
    }

    // 查询所用检查组数据 查询前先清空 套餐-检查组表的数据 和 清空套餐的价格
    @GetMapping("checkGroupXxqb.do/{id}")
    public List<CheckGroup> checkGroupXxqb(@PathVariable int id) {
        List<CheckGroup> list = checkGroupService.checkGroupXxqb(id);
        return list;
    }

    //给套餐添加检查组 和 重新计算价格
    @PostMapping("tctjjcz.do/{id}")
    public int  tctjjcz(@PathVariable int id,
                            @RequestBody CheckGroup[] checkGroups) {
        int tctjjcz = setmealService.tctjjcz(id, checkGroups);
        return tctjjcz;
    }

    //根据套餐id去查找它包含的检查组
    @GetMapping("ckjianchazu.do/{id}")
    public List<CheckGroup> ckjianchazu(@PathVariable int id) {
        return setmealService.ckjianchazu(id);
    }

    //查询所有的会员
    @GetMapping("memberqb.do")
    public List<Member> memberqb() {
        return setmealService.memberqb();
    }

    //查询所有的套餐
    @GetMapping("Setmealqb.do")
    public List<Setmeal> Setmealqb() {
        return setmealService.Setmealqb();
    }

    //确定预约
    @DeleteMapping("qdyy.do/{id}")
    public Result qdyy(@PathVariable int id) {
        Result num = orderService.qdyy(id);
        return num;
    }
    //取消预约
    @DeleteMapping("qxyy.do/{id}")
    public Result qxyy(@PathVariable int id) {
        Result num = orderService.qxyy(id);
        return num;
    }

    //设置预约人数
    @PostMapping("szrs.do")
    public Result szrs(@RequestBody OrderSetting orderSetting ) {

        Result szrs = orderSettingService.szrs(orderSetting);
        return szrs;
    }


        @GetMapping("ordersettingqb.do")
        public List<OrderSetting> ordersettingqb(){

         List<OrderSetting> list = orderSettingService.ordersettingqb();

        return list;
        }
}
